package com.cxrj.zhsq.redCommunity.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.cxrj.zhsq.redCommunity.dao.VolunteerMienMapper;
import com.cxrj.zhsq.redCommunity.entity.VolunteerMienWithBLOBs;
import com.cxrj.zhsq.redCommunity.service.VolunteerMienService;
import com.cxrj.zhsq.utils.SqlCondition;
import com.cxrj.zhsq.utils.UploadController;
/**
 * 志愿者风采业务处理层
 * @author wangm
 * @created @2018年5月17日-上午9:32:33
 *
 */
@Service
public class VolunteerMienServiceImpl implements VolunteerMienService {
	
	@Resource
	private VolunteerMienMapper volunteerMienMapper;

	@Override
	public Map<String, Object> selectVolunteerMienList(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> sqlMap = SqlCondition.getBaseCondition(request, response);
		int count = volunteerMienMapper.selectCount(sqlMap);
		List<Map<String, Object>> list = volunteerMienMapper.selectList(sqlMap);
		resultMap.put("total", count);
		resultMap.put("recordsFiltered", count);
		resultMap.put("rows", list);
		return resultMap;
	}

	@Override
	public Map<String, Object> insertVolunteerMien(VolunteerMienWithBLOBs model, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String userId = request.getSession().getAttribute("userId").toString();
		model.setUserId(userId);
		int n = volunteerMienMapper.insertSelective(model);
		resultMap.put("result", n);
		return resultMap;
	}

	@Override
	public Map<String, Object> updateVolunteerMien(VolunteerMienWithBLOBs model, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		int n = volunteerMienMapper.updateByPrimaryKeySelective(model);
		resultMap.put("result", n);
		return resultMap;
	}

	@Override
	public Map<String, Object> deleteVolunteerMien(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String vmId = request.getParameter("vmId");
		int n = 0;
		if(UploadController.deleteDir(vmId, request, response)) {
			n = volunteerMienMapper.deleteByPrimaryKey(vmId);
		}
		resultMap.put("result", n);
		return resultMap;
	}

	@Override
	public Map<String, Object> selectVolunteerMienById(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String vmId = request.getParameter("vmId");
		VolunteerMienWithBLOBs mien = volunteerMienMapper.selectByPrimaryKey(vmId);
		resultMap.put("result", mien);
		return resultMap;
	}

}
